package com.itheima.Controller;

import com.hmall.common.dto.Item;
import com.hmall.common.dto.PageDTO;
import com.itheima.dto.ItemDoc;
import com.itheima.dto.search;
import com.itheima.service.SearchService;
import org.checkerframework.checker.units.qual.A;
import org.elasticsearch.action.search.SearchResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {


    @Autowired
    private SearchService searchService;


    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody search search){

        PageDTO<ItemDoc> list = searchService.list(search);

        return list;
    }


    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String prefix){

       return searchService.suggestion(prefix);
    }


    @PostMapping("/filters")
    public Map<String,List<String>> filters(@RequestBody search search){

        Map<String,List<String>> map = searchService.filters(search);

        return map;
    }


}
